<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>毕业答辩</title>
    <link rel="stylesheet" type="text/css" href="../static/layui/css/layui.css"/>

</head>
<body>
<div class="layui-container">
    <div class="layui-row">
        <div class="layui-col-md8 layui-col-md-offset2">
            <form class="layui-form" action="" method="post">
                <div class="layui-form-item">
                    <label class="layui-form-label">题目</label>
                    <div class="layui-input-block">
                        <input type="text" id="tItem" name="tItem" autocomplete="off" class="layui-input"/>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">难度</label>
                    <div class="layui-input-block">
                        <div id="star">

                        </div>
                        <input type="hidden" id="diff" name="diff" value="1"/>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">时间</label>
                        <div class="layui-input-inline">
                            <input type="text" class="layui-input" id="time" name="time" placeholder="yyyy-MM-dd">
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">所属学校</label>
                        <div class="layui-input-inline">
                            <select class="layui-input" id="companyId" name="school.schoolId" lay-ignore
                                    onchange="c1(this.value)">
                                <option selected disabled>--------------请选择--------------</option>
                            </select>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">所属课程</label>
                        <div class="layui-input-inline">
                            <select class="layui-input" id="jobId" name="course.courseId" lay-ignore
                                    onchange="c2(this.value)">
                            </select>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label"></label>
                    <div class="layui-input-block">
                        <button type="button" class="layui-btn" lay-submit lay-filter="addTopic">添加</button>
                        <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>

<script src="../static/js/jquery-3.3.1.min.js" type="text/javascript" charset="utf-8"></script>
<script src="../static/layui/layui.js" charset="utf-8"></script>
<script>
    $(function () {
        $.post('/school_project/school/selectAll', function (res) {
            console.log(res)
            for (var i = 0; i < res.length; i++) {
                $('#companyId').append('<option value="' + res[i].schoolId + '">' + res[i].schoolName + '</option>')
            }
        }, 'json');
        c1(1);

    });

    function c1(index) {
        $.post('/school_project/course/selectAllBySchoolId', {'schoolId': index}, function (res) {
            $('#jobId').empty();
            for (var i = 0; i < res.length; i++) {
                // console.info(res.data[i].jobId+"..................")
                $('#jobId').append('<option value="'+res[i].courseId+'">' + res[i].courseName + '</option>')
            }
        }, 'json');
    }

    function c2(index) {

    }
    layui.use(['layer', 'form', 'element', 'rate', 'laydate'], function () {
        var layer = layui.layer,
            form = layui.form,
            element = layui.element;
        var rate = layui.rate;
        var laydate = layui.laydate;

        form.render('select');

        laydate.render({
            elem: '#time',
            done: function (value, date) {
                $('#time').val(value);
                console.info($('#time').val());
            }
        });

        rate.render({
            elem: '#star',
            value: 1,
            length: 5,
            text: true,
            choose: function (value) {
                console.info(value)
                $('#diff').val(value);
            }
        })
        form.on('submit(addTopic)', function (data) {
            console.log(data)
            $.post("/school_project/topic/insertTopic", data.field, function (res) {
                console.log(res)
                layer.confirm("添加成功",function () {
                    window.location.reload();
                });
            }, 'json');
            return false;
        })
    });
</script>

</body>
</html>
